package com.cskaoyan.service.wx.impl;


import com.cskaoyan.bean.po.MarketUser;
import com.cskaoyan.bean.po.WxUserIndexInfo;
import com.cskaoyan.bean.vo.wx.WxUserIndexVo;
import com.cskaoyan.mapper.MarketOrderMapper;
import com.cskaoyan.service.wx.WxUserService;
import com.cskaoyan.util.GetInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author jzp
 * @since 2022/11/23 09:11
 */
@Service
public class WxUserServiceImpl implements WxUserService {
    @Autowired
    MarketOrderMapper marketOrderMapper;

    @Override
    public WxUserIndexVo index() {
        WxUserIndexVo indexVo = new WxUserIndexVo();
        WxUserIndexVo.OrderDTO orderDTO = new WxUserIndexVo.OrderDTO();

        MarketUser wxLoginInfo = GetInfo.getWxLoginInfo();
        Integer userId = wxLoginInfo.getId();

        List<WxUserIndexInfo> wxUserIndexInfoList = marketOrderMapper.selectIndexInfo(userId);
        for (WxUserIndexInfo wxUserIndexInfo : wxUserIndexInfoList) {
            Integer status = wxUserIndexInfo.getStatus();
            int count = wxUserIndexInfo.getCount();
            if (status == 101) {
                orderDTO.setUnpaid(count);
            }
            if (status == 201) {
                orderDTO.setUnship(count);
            }
            if (status == 301) {
                orderDTO.setUnrecv(count);
            }
        }
        WxUserIndexInfo uncomment = marketOrderMapper.selectUncomment(userId);
        orderDTO.setUncomment(uncomment.getCount());
        if (orderDTO.getUncomment() == null) {
            orderDTO.setUncomment(0);
        }
        if (orderDTO.getUnpaid() == null) {
            orderDTO.setUnpaid(0);
        }
        if (orderDTO.getUnrecv() == null) {
            orderDTO.setUnrecv(0);
        }
        if (orderDTO.getUnship() == null) {
            orderDTO.setUnship(0);
        }
        indexVo.setOrder(orderDTO);
        return indexVo;
    }
}
